package content

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import cn.hutool.core.codec.Base64
import cn.hutool.crypto.SecureUtil
import theme.divider

/**
 *
 * @author：zooooooooy
 * @date: 2023/12/27 - 14:45
 */
@Composable
fun Md5Content() {

    Column(
        modifier = Modifier
            .fillMaxHeight()
            .fillMaxWidth(),
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally,
    ) {

        var text = remember { mutableStateOf("") }

        var resultText = remember { mutableStateOf("") }

        OutlinedTextField(
            modifier = Modifier
                .fillMaxWidth()
                .padding(20.dp)
                .height(100.dp),
            value = text.value,
            label = { Text(text = "原始字符串") },
            onValueChange = {
                text.value = it
                resultText.value = SecureUtil.md5(it)
            },
            textStyle = MaterialTheme.typography.body2.copy(
                fontWeight = FontWeight.ExtraLight
            ),
            colors = TextFieldDefaults.textFieldColors(
                backgroundColor = MaterialTheme.colors.surface,
                cursorColor = Color.White,
                leadingIconColor = Color.White,
                trailingIconColor = Color.White,
                textColor = Color.White
            )
        )

        Divider(color = divider)

        OutlinedTextField(
            modifier = Modifier
                .fillMaxWidth()
                .padding(20.dp)
                .height(100.dp),
            value = resultText.value,
            label = { Text(text = "结果字符串") },
            onValueChange = { },
            textStyle = MaterialTheme.typography.body2.copy(
                fontWeight = FontWeight.ExtraLight
            ),
            colors = TextFieldDefaults.textFieldColors(
                backgroundColor = MaterialTheme.colors.surface,
                cursorColor = Color.White,
                leadingIconColor = Color.White,
                trailingIconColor = Color.White,
                textColor = Color.White
            )
        )
    }

}

@Composable
fun Base64Content() {

    Column(
        modifier = Modifier
            .fillMaxHeight()
            .fillMaxWidth(),
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally,
    ) {

        var text = remember { mutableStateOf("") }

        var resultText = remember { mutableStateOf("") }

        OutlinedTextField(
            modifier = Modifier
                .fillMaxWidth()
                .padding(20.dp)
                .height(100.dp),
            value = text.value,
            label = { Text(text = "原始字符串") },
            onValueChange = {
                text.value = it
                resultText.value = Base64.encode(it)
            },
            textStyle = MaterialTheme.typography.body2.copy(
                fontWeight = FontWeight.ExtraLight
            ),
            colors = TextFieldDefaults.textFieldColors(
                backgroundColor = MaterialTheme.colors.surface,
                cursorColor = Color.White,
                leadingIconColor = Color.White,
                trailingIconColor = Color.White,
                textColor = Color.White
            )
        )

        Divider(color = divider)

        OutlinedTextField(
            modifier = Modifier
                .fillMaxWidth()
                .padding(20.dp)
                .height(100.dp),
            value = resultText.value,
            label = { Text(text = "结果字符串") },
            onValueChange = {
                resultText.value = it
                text.value = Base64.decodeStr(it)
            },
            textStyle = MaterialTheme.typography.body2.copy(
                fontWeight = FontWeight.ExtraLight
            ),
            colors = TextFieldDefaults.textFieldColors(
                backgroundColor = MaterialTheme.colors.surface,
                cursorColor = Color.White,
                leadingIconColor = Color.White,
                trailingIconColor = Color.White,
                textColor = Color.White
            )
        )
    }

}

@Composable
fun SHA1Content() {

    Column(
        modifier = Modifier
            .fillMaxHeight()
            .fillMaxWidth(),
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally,
    ) {

        var text = remember { mutableStateOf("") }

        var resultText = remember { mutableStateOf("") }

        OutlinedTextField(
            modifier = Modifier
                .fillMaxWidth()
                .padding(20.dp)
                .height(100.dp),
            value = text.value,
            label = { Text(text = "原始字符串") },
            onValueChange = {
                text.value = it
                resultText.value = SecureUtil.sha1(it)
            },
            textStyle = MaterialTheme.typography.body2.copy(
                fontWeight = FontWeight.ExtraLight
            ),
            colors = TextFieldDefaults.textFieldColors(
                backgroundColor = MaterialTheme.colors.surface,
                cursorColor = Color.White,
                leadingIconColor = Color.White,
                trailingIconColor = Color.White,
                textColor = Color.White
            )
        )

        Divider(color = divider)

        OutlinedTextField(
            modifier = Modifier
                .fillMaxWidth()
                .padding(20.dp)
                .height(100.dp),
            value = resultText.value,
            label = { Text(text = "结果字符串") },
            onValueChange = { },
            textStyle = MaterialTheme.typography.body2.copy(
                fontWeight = FontWeight.ExtraLight
            ),
            colors = TextFieldDefaults.textFieldColors(
                backgroundColor = MaterialTheme.colors.surface,
                cursorColor = Color.White,
                leadingIconColor = Color.White,
                trailingIconColor = Color.White,
                textColor = Color.White
            )
        )
    }

}
